import { AgreeAgreement } from '../NetServiceBase';
import { IsNullOrWhiteSpace } from '../../TYLibrary/Common/GlobalExtend';
import {
	TYConfig,
	Wx_Page,
	Wx_PageData,
	WXDataClassRuntimeDecorator
	} from '../EntityBase';

@WXDataClassRuntimeDecorator()
export class AgreementBasePageData extends Wx_PageData {
	public LoadFail: boolean = false;
	public ErrMessage: string = '';
}

export class AgreementBasePage extends Wx_Page {
	public Data = new AgreementBasePageData();

	async onGetUserInfo(e) {
		this.m_App_InitUserInfoAndCheckAuthInfo(async () => {
			await AgreeAgreement(TYConfig.AgreeAgreement, this.App.ModuleManager.MemberManager.LoginUser.OPENID);
			await this.OnAppInitReady();
			if(IsNullOrWhiteSpace(this.App.IndexPageType))
				throw "IndexPageType属性不能为空!";
			else
				wx.switchTab({ url: this.App.IndexPageType });
		});
	}

	/**
     * APP初始化完成
     *
     * @memberof AgreementBasePage
     */
	public async OnAppInitReady() { }

	// public async Colse(e) {
	// 	console.log("close");
	// 	wx.navigateBack({ delta: 10 });
	// }

	public async RetryHandler(e: any) {
		this.Data.LoadFail=false;
		await this.Data.ApplyChange(this);
		await this.InitData(null);
	}
}
